<?php


namespace app\model\partner;


use app\model\admin\AdminUserModel;
use app\model\user\UserModel;
use think\Model;

class OrderLogModel extends Model
{
    protected $name = 'order_log';
    protected $autoWriteTimestamp = true;

    protected $append = ['type_txt'];

    protected $typeArr = [
        1 => '用户取消',
        2 => '教练拒接',
        3 => '教练放置大厅',
        4 => '后台取消',
        5 => '后台放置大厅',
    ];

    public function admin()
    {
        return $this->hasOne(AdminUserModel::class, 'id', 'admin_id')->bind(['admin_name' => 'nick']);
    }

    public function user()
    {
        return $this->hasOne(UserModel::class, 'id', 'user_id')->bind(['user_name' => 'username']);
    }

    public function coach()
    {
        return $this->hasOne(UserPartnerModel::class, 'id', 'coach_id')->bind(['coach_name' => 'username']);
    }

    public function orderInfo()
    {
        return $this->hasOne(EscortMenuReserveOrderModel::class, 'id', 'order_id')->bind(['order_sn']);
    }

    public function getTypeTxtAttr($value, $data)
    {
        if (!isset($data['type'])) {
            return '';
        }
        return $this->typeArr[$data['type']];
    }
}